<?php

/**
 * 发现首页文件
 * ============================================================================
 * $Author: 王海龙 $
 * $Id: index.php 2015-01-01 王海龙 $
*/

define('IS_MOBILE', true);
require(dirname(__FILE__) . '/../includes/init.php');
include_once(ROOT_PATH . '/includes/funTvd.php');
@ini_set('display_errors',        1);

/* 初始化赋值模板 */
assign_template();

/* 如果是AJAX异步加载发现文章，则直接返回数据 */
if (!empty($_GET['isAjax'])) {
    /* 设置页码 */
    $page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
    $tvdList = getIndexTvdList(($page-1)*5+1, 5);
    $smarty->assign('tvdList', $tvdList);
    $smarty->assign('page', $page);
    if (!empty($tvdList)) {
        $result['error'] = 0;
        $result['count'] = count($tvdList);
        $result['content'] = $smarty->fetch('tvd/indexTvdList.lbi');
    } else {
        $result['error'] = 1;
    }
    echo JSON()->encode($result, false);
    exit;
}
$smarty->assign('page_title',      htmlspecialchars($_CFG['shop_title'])); // 首页页面标题
$smarty->assign('keywords',        htmlspecialchars($_CFG['shop_keywords'])); // 首页SEO网站关键词
$smarty->assign('description',     htmlspecialchars($_CFG['shop_desc'])); // 首页SEO网站描述
$smarty->assign('banner', getAds(55)); // 轮播广告图
$tvdList = getIndexTvdList(0, 1);
$smarty->assign('tvd', $tvdList[0]); // 轮播广告图

$smarty->display('tvd/index.dwt');
